#pragma once
#include "global.h"

template<class T>
class Singleton {
protected:
    Singleton() = default;

    static std::shared_ptr<T> _instance;

public:
    Singleton(const Singleton &) = delete;

    Singleton &operator=(const Singleton &) = delete;

    static std::shared_ptr<T> GetInstance() {
        static std::once_flag _flag;
        std::call_once(_flag, [&]() {
            _instance = std::shared_ptr<T>(new T());
        });
        return _instance;
    }

    void PrintAddress() {
        std::cout << _instance.get() << std::endl;
    }

    virtual ~Singleton() {
        std::cout << "this singleton destruct" << std::endl;
    }
};

template<class T>
std::shared_ptr<T> Singleton<T>::_instance = nullptr;


